﻿using Common.Communal;
using MediatR;
using System.Api.Write.Applications.Commands.Users;
using System.Services.Users;

namespace System.Api.Write.Applications.CommandHandlers.Users
{
    /// <summary>
    /// 用户删除命令处理程序
    /// </summary>
    public class UserDeleteCommandHandler : IRequestHandler<UserDeleteCommand, ApiResult<int>>
    {
        /// <summary>
        /// 用户服务接口
        /// </summary>
        private readonly IUserService service;
        /// <summary>
        /// 构造函数，注入用户服务接口
        /// </summary>
        /// <param name="service">用户服务接口</param>
        public UserDeleteCommandHandler(IUserService service)
        {
            this.service = service;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>返回结果</returns>
        public async Task<ApiResult<int>> Handle(UserDeleteCommand request, CancellationToken cancellationToken)
        {
            return await service.Delete(request.Id);
        }
    }
}
